package com.ym.controller.management;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ym.core.annotation.Log;
import com.ym.core.domain.APIResponse;
import com.ym.core.domain.BaseController;
import com.ym.medical.domain.entity.AppVersionEntity;
import com.ym.medical.domain.param.AppVersionParam;
import com.ym.medical.service.IAppVersionSV;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * APP版本管理
 *
 * @author: 李涛
 * @version: 2019年10月15日 8:47
 */
@Api(tags = "APP版本管理")
@RestController
@RequestMapping("/management/version")
public class AppVersionController extends BaseController {

	@Autowired
	private IAppVersionSV appVersionSV;

	@Log(dataBase = false, printBody = false)
	@ApiOperation(value = "获取版本列表")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "pageNo", required = false, paramType = "query"),
			@ApiImplicitParam(name = "limit", required = false, paramType = "query"),
	})
	@GetMapping("/version")
	public APIResponse<PageInfo<AppVersionEntity>> version(
			@RequestParam(name = "pageNo", required = false, defaultValue = "1")
					int pageNo,
			@RequestParam(name = "limit", required = false, defaultValue = "10")
					int limit,
			AppVersionParam appVersionModel
	) {
		PageHelper.startPage(pageNo,limit);
		List<AppVersionEntity> list = appVersionSV.selectList(appVersionModel.covert());
		return successPage(list);
	}

	@Log
	@ApiOperation(value = "新增修改")
	@PostMapping(value = "/update")
	public APIResponse<PageInfo<AppVersionEntity>> update(
			@Valid @NotNull AppVersionParam appVersion
	) {
		appVersionSV.updateById(appVersion.covert());
		return APIResponse.success();
	}

	@Log
	@ApiOperation(value = "删除")
	@PostMapping("/delete")
	public APIResponse<PageInfo<AppVersionEntity>> delete(
			@Valid @RequestBody Long[] ids
	) {
		appVersionSV.deleteByIds(ids);
		return APIResponse.success();
	}
}
